/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wat.ziszcommon.remote;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author Marcin
 */
public class CryptoUtils {

    public static String md5(byte[] data) {
        try {
            MessageDigest md5algorithm = MessageDigest.getInstance("MD5");
            md5algorithm.reset();
            md5algorithm.update(data);
            byte md5digest[] = md5algorithm.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i=0;i<md5digest.length;i++) {
                if(0<=md5digest[i] && md5digest[i]<16) {
                    hexString.append("0" + Integer.toHexString(0xFF & md5digest[i]));
                } else {
                    hexString.append(Integer.toHexString(0xFF & md5digest[i]));
                }
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException ex) {
        }
        return null;
    }

}
